<?php
declare(strict_types=1);

namespace Zms\Guard;

use Attribute;
use Hyperf\Di\Annotation\AbstractAnnotation;

/**
 * 权限注解，允许运行在类和方法上
 */
#[Attribute(Attribute::TARGET_METHOD | Attribute::TARGET_CLASS)]
class Auth extends AbstractAnnotation
{

    public ?array $label = [];

    /**
     * @var ?string 所属用户组
     */
    public ?string $guard = null;

    /**
     * @var ?string 权限值
     */
    public ?string $sign = null;

    /**
     * @var bool 是否允许游客访问
     */
    public bool $tourist = false;


    /**
     * @var ?array 依赖权限
     */
    public ?array $relyon = null;


    /**
     * @var ?string 权限前缀
     */
    public ?string $prefix = null;


    /**
     * @var ?array 访问模式
     */
    public ?array $mode = null;

    /**
     * 移除注解
     * @var bool
     */
    public bool $remove = false;

    /**
     * get|GET 代表只记录get请求
     * post|POST 代表只记录POST请求
     * true 代表记录一切信息
     * false 代表不记录任何信息
     * string 代表日志标题
     * @var bool 是否记录日志
     */
    public mixed $logger = true;

    /**
     * 需要记录的参数，空数组代表所有参数记录
     * @var array
     */
    public array $record = [];


    /**
     * 是否在切片中检查权限
     * @var bool
     */
    public bool $check = true;


    /**
     * 描述
     * @var string|null
     */
    public ?string $describe = null;


    /**
     * 分属哪个项目
     * @var string|null
     */
    public ?string $app = null;


    /**
     * 是否在aop中执行过程,设置null时默认值为true
     * @var bool
     */
    public ?bool $process = null;


    /**
     * 绑定视图
     * @var string|null
     */
    public ?string $view = null;


    public function __construct(
        ?string $guard = null,  //权限认证标识
        ?array  $label = [],
        ?string $sign = null,
        bool    $tourist = false,
        ?array  $relyon = null,
        ?string $prefix = null,
        ?array  $mode = null,
        mixed   $logger = true,
        array   $record = [],
        bool    $check = true,
        ?string $describe = null,
        ?string $app = null,
        ?string $view = null,
        ?bool   $process = null,
        bool    $remove = false
    )
    {
        $this->guard = $guard;
        $this->label = $label;
        $this->sign = $sign;
        $this->tourist = $tourist;
        $this->mode = $mode;
        $this->logger = $logger;
        $this->relyon = $relyon;
        $this->prefix = $prefix;
        $this->record = $record;
        $this->check = $check;
        $this->describe = $describe;
        $this->app = $app;
        $this->view = $view;
        $this->process = $process;
        $this->remove = $remove;
    }
}